package com.burstly.lib.component;

import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout.LayoutParams;
import com.burstly.lib.component.networkcomponent.HierarchyAwareLayout;
import com.burstly.lib.component.networkcomponent.burstly.BurstlyFullscreenActivity;
import com.burstly.lib.component.networkcomponent.burstly.FullscreenOverlayContainer;
import com.burstly.lib.component.networkcomponent.burstly.OverlayContainer.IOverlayListener;
import com.burstly.lib.network.ResponseObject;
import com.burstly.lib.network.beans.DestinationType;
import com.burstly.lib.network.beans.RequestData;
import com.burstly.lib.network.beans.RequestData.Request;
import com.burstly.lib.network.beans.ResponseBean;
import com.burstly.lib.network.beans.ResponseBean.ResponseData;
import com.burstly.lib.network.beans.TrackClickRequest;
import com.burstly.lib.network.beans.TrackClickRequest.Request;
import com.burstly.lib.network.beans.TrackClickResult;
import com.burstly.lib.network.beans.TrackShowRequest;
import com.burstly.lib.network.beans.TrackShowRequest.Request;
import com.burstly.lib.network.beans.cookie.CookieManager;
import com.burstly.lib.network.request.SafeAsyncTask;
import com.burstly.lib.persistance.ResponseSaver;
import com.burstly.lib.service.ServerConfigurationService;
import com.burstly.lib.service.ServerConfigurationService.IServerConfigurable;
import com.burstly.lib.ui.BurstlyView;
import com.burstly.lib.ui.LastBurstlyError;
import com.burstly.lib.util.LoggerExt;
import com.burstly.lib.util.Utils;
import com.burstly.lib.util.Utils.DebugWrapper;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import junit.framework.Assert;

class AdaptorController
  implements IAdaptorController, OverlayContainer.IOverlayListener, ServerConfigurationService.IServerConfigurable
{
  private static final String FLAG_GESTURE_DEBUG = "gestureDebug";
  private static final String GESTURE_ON_FLAG = "on";
  static final LoggerExt LOG = LoggerExt.getInstance();
  private static final SecureRandom SECURE_RANDOM = new SecureRandom();
  final IBurstlyAdaptor mAdaptor;
  AdaptorListener mAdaptorListener;
  private IInternalBurstlyAdListener mBurstlyListener;
  private String mBurstlyViewId;
  private Map<String, String> mClientTargetParams;
  private final Context mContext;
  private ComponentState mCurrentState;
  private Map<String, ?> mCustomNetworkParams;
  Utils.DebugWrapper mDebugger;
  volatile boolean mDestroyed;
  private List<FailedToShow> mFailedToShow;
  private boolean mIsDebugGestureOn;
  boolean mIsInterstitial;
  private Boolean mIsInterstitialMode;
  boolean mIsPrefetchRequest;
  private IAdaptorController.IComponentQueueLifecycleListener mLifeCycleListener;
  String mNetworkName;
  ResponseObject mParams;
  BurstlyView mParent;
  private ResponseSaver<ResponseBean> mResponseSaver;
  String mTag;
  private final TrackClickRequest mTrackClickRequest;
  private TrackRequestSender mTrackRequestSender;
  private final TrackShowRequest mTrackShowRequest;
  private final Handler mUiThread;
  private final ViewHolder mViewHolder;

  AdaptorController(ControllerConfig paramControllerConfig)
  {
    this.mAdaptor = paramControllerConfig.getAdaptor();
    this.mContext = paramControllerConfig.getContext();
    this.mUiThread = new Handler(Looper.getMainLooper());
    this.mViewHolder = new ViewHolder();
    this.mTrackShowRequest = new TrackShowRequest();
    TrackShowRequest.Request localRequest = this.mTrackShowRequest.getData();
    localRequest.setUserAgentInfo(Utils.getUserAgent(this.mContext));
    localRequest.setApplicationVersion(Utils.getApplicationVersionName());
    this.mTrackClickRequest = new TrackClickRequest();
    this.mTrackClickRequest.getData().setEncDevId(Utils.encryptedDeviceId(this.mContext));
    this.mFailedToShow = new ArrayList();
    String str = paramControllerConfig.getCreativeData().getFeedName();
    if (str != null);
    while (true)
    {
      this.mNetworkName = str;
      this.mTrackRequestSender = new TrackRequestSender(this);
      createControllerState(paramControllerConfig);
      setBurstlyViewId(paramControllerConfig.getBurstlyViewId());
      ServerConfigurationService.addRecipient(this);
      return;
      str = this.mAdaptor.getNetworkName();
    }
  }

  private boolean bannerShown()
  {
    return !isInterstitial();
  }

  private static void checkHasNoParent(View paramView)
    throws IllegalStateException
  {
    if ((paramView != null) && (paramView.getParent() != null))
      throw new IllegalStateException("View MUST NOT have a parent!");
  }

  private void createControllerState(ControllerConfig paramControllerConfig)
  {
    this.mCurrentState = new ComponentState();
    this.mCurrentState.setFullResponse(paramControllerConfig.getResponseBean());
    this.mCurrentState.setResponseData(paramControllerConfig.getCreativeData());
    this.mCurrentState.setRequestData(paramControllerConfig.getRequestData());
  }

  private boolean forceInterstitial()
  {
    Integer localInteger = getCurrentAdData().getIsInterstital();
    return (localInteger != null) && (localInteger.intValue() == 1);
  }

  private ResponseBean getFullResponse()
  {
    return this.mCurrentState.getFullResponse();
  }

  private ResponseBean.ResponseData getNotExpiredResponseData()
  {
    ResponseBean.ResponseData localResponseData = getCurrentAdData();
    if (Utils.isAdExpired(localResponseData))
    {
      LOG.logDebug(this.mTag, "Ad expired {0}.", new Object[] { localResponseData });
      if (getFullResponse().isIsLoadedFromCache())
        this.mResponseSaver.deleteLastResponse();
      localResponseData = null;
    }
    return localResponseData;
  }

  private Number getSessionLength(ResponseObject paramResponseObject)
  {
    Integer localInteger1 = getCurrentAdData().getSessionLength();
    if (localInteger1 != null)
      return localInteger1;
    Object localObject1 = paramResponseObject.get("sessionLength");
    Object localObject2 = null;
    try
    {
      if ((localObject1 instanceof Number))
      {
        localObject2 = (Number)localObject1;
      }
      else
      {
        boolean bool = localObject1 instanceof String;
        localObject2 = null;
        if (bool)
        {
          Integer localInteger2 = Integer.valueOf(Integer.parseInt((String)localObject1));
          localObject2 = localInteger2;
        }
      }
    }
    catch (Exception localException)
    {
      LOG.logWarning(this.mTag, "sessionLength is not a number.", new Object[0]);
    }
    return localObject2;
  }

  private boolean handleAsBanner()
  {
    return !this.mIsInterstitial;
  }

  static void handleErrorFlow(AdaptorController paramAdaptorController, Throwable paramThrowable)
  {
    String str1 = Log.getStackTraceString(paramThrowable);
    if (paramAdaptorController.mParams != null);
    for (String str2 = paramAdaptorController.mParams.toString(); ; str2 = null)
    {
      LoggerExt localLoggerExt = LOG;
      String str3 = paramAdaptorController.mTag;
      Object[] arrayOfObject = new Object[2];
      arrayOfObject[0] = paramAdaptorController.mNetworkName;
      arrayOfObject[1] = str2;
      localLoggerExt.logError(str3, "Caught an exception while showing ad for {0} component.\nCaused response: {1}", arrayOfObject);
      LOG.logError(paramAdaptorController.mTag, "Stacktrace : {0}", new Object[] { str1 });
      paramAdaptorController.mParent.setLastError(LastBurstlyError.ERROR_PROCESSING_PARAMS);
      paramAdaptorController.mAdaptorListener.failedToLoad(paramAdaptorController.mNetworkName, paramAdaptorController.mIsInterstitial, paramThrowable.getMessage());
      return;
    }
  }

  static void handleServerResponse(AdaptorController paramAdaptorController)
  {
    IBurstlyAdaptor localIBurstlyAdaptor = paramAdaptorController.mAdaptor;
    ViewHolder localViewHolder = paramAdaptorController.mViewHolder;
    IBurstlyAdaptor.BurstlyAdType localBurstlyAdType = localIBurstlyAdaptor.getAdType();
    if (paramAdaptorController.isPrefetchRequest())
    {
      if (localBurstlyAdType == IBurstlyAdaptor.BurstlyAdType.INTERSTITIAL_AD_TYPE)
      {
        localIBurstlyAdaptor.precacheInterstitialAd();
        return;
      }
      View localView2 = localIBurstlyAdaptor.precacheAd();
      checkHasNoParent(localView2);
      localViewHolder.setPrecachedAdView(wrap(paramAdaptorController, localIBurstlyAdaptor, localView2));
      return;
    }
    View localView1 = localIBurstlyAdaptor.getNewAd();
    checkHasNoParent(localView1);
    localViewHolder.setAdView(wrap(paramAdaptorController, localIBurstlyAdaptor, localView1));
  }

  private void initAutorefresh(ResponseObject paramResponseObject)
  {
    if (!this.mIsPrefetchRequest)
    {
      Number localNumber = getSessionLength(paramResponseObject);
      IAdaptorController.IComponentQueueLifecycleListener localIComponentQueueLifecycleListener = getLifeCycleListener();
      if ((localNumber != null) && (localNumber.intValue() > 0) && (localIComponentQueueLifecycleListener != null))
      {
        LOG.logInfo(this.mTag, "Session length presents in response: {0}. Overriding current autorefresh state...", new Object[] { localNumber });
        localIComponentQueueLifecycleListener.startAutorefreshByParam(localNumber.intValue());
      }
    }
  }

  private boolean isInterstitial()
  {
    return ((handleAsBanner()) && (forceInterstitial())) || (!handleAsBanner());
  }

  private void notifySuccessfullyShowed()
  {
    if (bannerShown())
      this.mParent.setDisplayedBannerController(this);
    while (true)
    {
      this.mBurstlyListener.didLoad(this.mNetworkName, isInterstitial());
      showComponent();
      this.mDebugger.logAll();
      this.mAdaptor.endTransaction(IBurstlyAdaptor.TransactionCode.CODE_SUCCESS);
      this.mLifeCycleListener.successToshow(new ArrayList(this.mFailedToShow));
      this.mFailedToShow.clear();
      return;
      this.mParent.setDisplayedInterstitialController(this);
    }
  }

  private void saveCookies()
  {
    if (this.mCurrentState != null)
      CookieManager.saveCookies(getCurrentAdData().getCookie());
  }

  private void saveSuccessResponse()
  {
    if (this.mResponseSaver.isAllowedToSave())
    {
      ResponseBean localResponseBean = getFullResponse();
      ResponseBean.ResponseData localResponseData = getCurrentAdData();
      if (Utils.isThirdPartySDK(localResponseData))
      {
        localResponseBean.setData(new ResponseBean.ResponseData[] { localResponseData });
        this.mResponseSaver.saveLastResponse(localResponseBean);
      }
    }
  }

  private void sendTrackClickRequest(String paramString)
  {
    this.mTrackRequestSender.onClick(paramString);
  }

  private void setBurstlyViewId(String paramString)
  {
    this.mBurstlyViewId = paramString;
    this.mTag = (paramString + " adaptor controller -> " + this.mNetworkName);
    this.mDebugger = Utils.DebugWrapper.getDebugger(this.mTag);
    this.mTrackRequestSender.setBurstlyViewId();
  }

  private static ViewGroup wrap(AdaptorController paramAdaptorController, IBurstlyAdaptor paramIBurstlyAdaptor, View paramView)
  {
    if (paramView != null)
      return new HierarchyAwareLayout(paramAdaptorController.mContext, paramView, paramIBurstlyAdaptor);
    return null;
  }

  void addComponentToFailedCollector()
  {
    ResponseBean.ResponseData localResponseData = getCurrentAdData();
    if (localResponseData != null)
    {
      RequestData localRequestData = this.mCurrentState.getRequestData();
      this.mFailedToShow.add(new FailedToShow(localRequestData.getPublisher(), localRequestData.getZone(), localResponseData.getCrid()));
    }
  }

  void addComponentToParent(View paramView)
  {
    if ((this.mParent != null) && (paramView != null) && (!this.mDestroyed))
    {
      paramView.setId(Math.abs(SECURE_RANDOM.nextInt()));
      this.mParent.addView(paramView);
      return;
    }
    LOG.logError(this.mTag, "Parent or component view is NULL or has been destroyed! Can not add component  to parent.", new Object[0]);
  }

  void beginTransaction(ResponseObject paramResponseObject)
  {
    this.mParams = paramResponseObject;
    if (paramResponseObject != null)
    {
      if ((this.mClientTargetParams != null) && (this.mClientTargetParams.size() > 0))
        paramResponseObject.put("clientTargetingParams", this.mClientTargetParams);
      if (this.mCustomNetworkParams != null)
      {
        LoggerExt localLoggerExt3 = LOG;
        String str3 = this.mTag;
        Object[] arrayOfObject3 = new Object[1];
        arrayOfObject3[0] = this.mNetworkName;
        localLoggerExt3.logInfo(str3, "Set custom adapter parameters for network: {0}", arrayOfObject3);
        paramResponseObject.put(this.mNetworkName, this.mCustomNetworkParams);
      }
      if (this.mIsInterstitialMode != null)
      {
        paramResponseObject.put("isCodeValueInterstitial", this.mIsInterstitialMode);
        LoggerExt localLoggerExt2 = LOG;
        String str2 = this.mTag;
        Object[] arrayOfObject2 = new Object[2];
        arrayOfObject2[0] = this.mIsInterstitialMode;
        arrayOfObject2[1] = this.mNetworkName;
        localLoggerExt2.logInfo(str2, "Set iterstitial mode {0} for network: {1}", arrayOfObject2);
      }
      String[] arrayOfString = this.mCurrentState.getRequestData().getData().getAdSize();
      if ((arrayOfString != null) && (arrayOfString.length == 1))
      {
        paramResponseObject.put("adSizeCodeValue", arrayOfString[0]);
        LoggerExt localLoggerExt1 = LOG;
        String str1 = this.mTag;
        Object[] arrayOfObject1 = new Object[2];
        arrayOfObject1[0] = arrayOfString[0];
        arrayOfObject1[1] = this.mNetworkName;
        localLoggerExt1.logInfo(str1, "Set ad size {0} for network: {1}", arrayOfObject1);
      }
      Boolean localBoolean = Utils.forceHardwareAccelerationTo(this.mCurrentState.getResponseData());
      if (localBoolean != null)
        paramResponseObject.put("OverrideHardwareAccelerationTo", localBoolean);
      this.mAdaptor.startTransaction(paramResponseObject);
      return;
    }
    throw new IllegalStateException("Error parsing server paramters");
  }

  public void click()
  {
    this.mBurstlyListener.adNetworkWasClicked(this.mNetworkName);
    sendTrackClickRequest(this.mAdaptorListener.getClickRedirectUrl());
    if ((DestinationType.None.getValue().equals(getCurrentAdData().getDestType())) && (BurstlyFullscreenActivity.sActiveActivity != null))
    {
      Activity localActivity = (Activity)BurstlyFullscreenActivity.sActiveActivity.get();
      if (localActivity != null)
        localActivity.finish();
    }
  }

  public void configure(Map<String, Object> paramMap)
  {
    String str = (String)paramMap.get("gestureDebug");
    LOG.logDebug(this.mTag, "New value for gestureState: {0}", new Object[] { str });
    setIsDebugGestureOn("on".equals(str));
  }

  protected void defaultPostClickCallback(TrackClickResult paramTrackClickResult)
  {
  }

  public void destroy()
  {
    this.mDestroyed = true;
    this.mAdaptor.destroy();
  }

  public boolean equals(Object paramObject)
  {
    if (this == paramObject);
    AdaptorController localAdaptorController;
    do
    {
      do
      {
        return true;
        if (paramObject == null)
          return false;
        if (getClass() != paramObject.getClass())
          return false;
        localAdaptorController = (AdaptorController)paramObject;
        if (getViewId() == null)
        {
          if (localAdaptorController.getViewId() != null)
            return false;
        }
        else if (!getViewId().equals(localAdaptorController.getViewId()))
          return false;
        if (getNetworkName() != null)
          break;
      }
      while (localAdaptorController.getNetworkName() == null);
      return false;
    }
    while (getNetworkName().equals(localAdaptorController.getNetworkName()));
    return false;
  }

  protected void fillUpWithCurrentResponseData(ResponseObject paramResponseObject)
  {
    if (paramResponseObject != null)
    {
      paramResponseObject.put("componentState", this.mCurrentState);
      paramResponseObject.put("context", getContext());
    }
  }

  public IBurstlyAdaptor getAdaptor()
  {
    return this.mAdaptor;
  }

  public IInternalBurstlyAdListener getBursltlyAdListener()
  {
    return this.mBurstlyListener;
  }

  Context getContext()
  {
    return this.mContext;
  }

  public ResponseBean.ResponseData getCurrentAdData()
  {
    return this.mCurrentState.getResponseData();
  }

  ComponentState getCurrentState()
  {
    return this.mCurrentState;
  }

  protected void getDataForComponent()
  {
    new ParseParamsAsyncTask(this).execute(new Void[0]);
  }

  IAdaptorController.IComponentQueueLifecycleListener getLifeCycleListener()
  {
    return this.mLifeCycleListener;
  }

  public String getNetworkName()
  {
    return this.mAdaptor.getNetworkName();
  }

  TrackClickRequest getTrackClickRequest()
  {
    return this.mTrackClickRequest;
  }

  TrackShowRequest getTrackShowRequest()
  {
    return this.mTrackShowRequest;
  }

  View getView()
  {
    View localView = this.mViewHolder.getPrecachedAdView();
    if (localView != null)
      return localView;
    return this.mViewHolder.getAdView();
  }

  public String getViewId()
  {
    return this.mBurstlyViewId;
  }

  void handleSuccessToLoad()
  {
    saveSuccessResponse();
    if (isPrefetchRequest())
    {
      handleSuccessToPrecache();
      return;
    }
    saveCookies();
    sendTrackShowRequest();
    notifySuccessfullyShowed();
  }

  void handleSuccessToPrecache()
  {
    LOG.logInfo(this.mTag, "Component was created in prefetch mode. It will not be shown until request next ad.", new Object[0]);
    this.mBurstlyListener.didPrecacheAd(this.mNetworkName);
  }

  public int hashCode()
  {
    int i;
    int j;
    int k;
    if (getViewId() == null)
    {
      i = 0;
      j = 31 * (i + 31);
      String str = getNetworkName();
      k = 0;
      if (str != null)
        break label45;
    }
    while (true)
    {
      return j + k;
      i = getViewId().hashCode();
      break;
      label45: k = getNetworkName().hashCode();
    }
  }

  public void hideComponent()
  {
    this.mParent.removeAllViews();
  }

  public boolean isConstantRecepient()
  {
    return false;
  }

  boolean isContinueProcessing(ResponseObject paramResponseObject)
  {
    boolean bool;
    IBurstlyAdaptor.BurstlyAdType localBurstlyAdType;
    if (paramResponseObject != null)
    {
      bool = true;
      if (bool)
      {
        initAutorefresh(paramResponseObject);
        if (this.mIsPrefetchRequest)
        {
          localBurstlyAdType = this.mAdaptor.getAdType();
          if (localBurstlyAdType != IBurstlyAdaptor.BurstlyAdType.UNKNOWN_AD_TYPE)
            break label66;
          bool = false;
          LOG.logInfo(this.mTag, "Current adaptor does not support precaching because BurstlyAdType returned from adaptor is BurstlyAdType.UNKNOWN_AD_TYPE.", new Object[0]);
        }
      }
    }
    label66: 
    do
    {
      do
      {
        return bool;
        bool = false;
        break;
      }
      while (localBurstlyAdType != IBurstlyAdaptor.BurstlyAdType.INTERSTITIAL_AD_TYPE);
      bool = this.mAdaptor.supports(IBurstlyAdaptor.AdaptorAction.PRECACHE_INTERSTITIAL.getCode());
    }
    while (bool);
    LOG.logInfo(this.mTag, "Current adaptor does not support interstitial precaching.", new Object[0]);
    return bool;
  }

  public boolean isDebugGestureOn()
  {
    return this.mIsDebugGestureOn;
  }

  public boolean isPrefetchRequest()
  {
    return this.mIsPrefetchRequest;
  }

  void notifyFailed(boolean paramBoolean)
  {
    this.mDebugger.logAll();
    this.mAdaptor.endTransaction(IBurstlyAdaptor.TransactionCode.CODE_FAILED);
    this.mBurstlyListener.failedToLoad(this.mNetworkName);
    if (!paramBoolean)
      this.mLifeCycleListener.failedToShow(new ArrayList(this.mFailedToShow));
    while (true)
    {
      this.mFailedToShow.clear();
      return;
      this.mBurstlyListener.failedToDisplayAds();
    }
  }

  public void onCloseOverlay()
  {
    this.mBurstlyListener.onHideFullscreen(new IBurstlyAdaptorListener.FullscreenInfo(this.mNetworkName, true));
  }

  public void onShowOverlay()
  {
    this.mBurstlyListener.onShowFullscreen(new IBurstlyAdaptorListener.FullscreenInfo(this.mNetworkName, true));
  }

  public void pause()
  {
    this.mAdaptor.pause();
  }

  public void resume()
  {
    this.mAdaptor.resume();
  }

  void sendTrackShowRequest()
  {
    this.mTrackRequestSender.onShow();
  }

  void setAdaptorListener()
  {
    this.mAdaptor.setAdaptorListener(this.mAdaptorListener);
  }

  public void setBursltlyAdListener(IInternalBurstlyAdListener paramIInternalBurstlyAdListener)
  {
    Assert.assertNotNull("Burstly listener can not be null", paramIInternalBurstlyAdListener);
    this.mBurstlyListener = paramIInternalBurstlyAdListener;
  }

  public void setClientTargetParams(Map<String, String> paramMap)
  {
    this.mClientTargetParams = paramMap;
  }

  public void setCustomNetworkParams(Map<String, ?> paramMap)
  {
    this.mCustomNetworkParams = paramMap;
  }

  public void setInterstitialMode(boolean paramBoolean)
  {
    this.mIsInterstitialMode = Boolean.valueOf(paramBoolean);
  }

  public void setIsDebugGestureOn(boolean paramBoolean)
  {
    this.mIsDebugGestureOn = paramBoolean;
  }

  public void setLifeCycleListener(IAdaptorController.IComponentQueueLifecycleListener paramIComponentQueueLifecycleListener)
  {
    this.mLifeCycleListener = paramIComponentQueueLifecycleListener;
  }

  public void setParent(BurstlyView paramBurstlyView)
  {
    if (this.mParent == null)
    {
      Assert.assertNotNull("Parent can not be null", paramBurstlyView);
      this.mParent = paramBurstlyView;
    }
  }

  public void setPrefetchedRequest(boolean paramBoolean)
  {
    this.mIsPrefetchRequest = paramBoolean;
  }

  public void setResponseSaver(ResponseSaver<ResponseBean> paramResponseSaver)
  {
    this.mResponseSaver = paramResponseSaver;
  }

  public void showComponent()
  {
    if ((!this.mIsPrefetchRequest) && (handleAsBanner()))
    {
      if (!forceInterstitial())
        this.mUiThread.post(new ViewSwitcher(this));
    }
    else
      return;
    View localView = getView();
    if (localView != null)
    {
      AdaptorCustomFullscreen localAdaptorCustomFullscreen = new AdaptorCustomFullscreen(this.mContext);
      localAdaptorCustomFullscreen.addView(localView);
      FullscreenOverlayContainer localFullscreenOverlayContainer = new FullscreenOverlayContainer(localAdaptorCustomFullscreen, this.mNetworkName);
      localFullscreenOverlayContainer.setInterstitialShowtime(getCurrentAdData().getInterstitialShowtime());
      localFullscreenOverlayContainer.setOverlayListener(this);
      localFullscreenOverlayContainer.showOverlayed();
      localView.setTag(localFullscreenOverlayContainer);
      return;
    }
    LOG.logError(this.mTag, "View to show as cusom interstitial is null. This could be cased by invalid success notification from ad network.", new Object[0]);
  }

  public void showPrecachedAd()
  {
    if (Utils.isAdExpired(getCurrentAdData()))
    {
      LOG.logDebug(this.mTag, "Cached ad expired!", new Object[0]);
      notifyFailed(true);
      this.mParent.setLastError(LastBurstlyError.CACHE_EXPIRED);
      this.mViewHolder.setPrecachedAdView(null);
      return;
    }
    saveCookies();
    IBurstlyAdaptor.BurstlyAdType localBurstlyAdType = this.mAdaptor.getAdType();
    notifySuccessfullyShowed();
    if (localBurstlyAdType == IBurstlyAdaptor.BurstlyAdType.INTERSTITIAL_AD_TYPE)
    {
      this.mAdaptor.showPrecachedInterstitialAd();
      return;
    }
    sendTrackShowRequest();
  }

  public void start()
  {
    LoggerExt localLoggerExt = LOG;
    String str = this.mTag;
    Object[] arrayOfObject = new Object[1];
    arrayOfObject[0] = this.mNetworkName;
    localLoggerExt.logInfo(str, "Server has passed an {0} advertise...", arrayOfObject);
    this.mBurstlyListener.attemptingToLoad(this.mNetworkName);
    LOG.logInfo(this.mTag, "Try to get data for this component if any...", new Object[0]);
    ResponseBean.ResponseData localResponseData = getNotExpiredResponseData();
    if (localResponseData != null)
    {
      this.mAdaptorListener = new AdaptorListener(this);
      LOG.logInfo(this.mTag, localResponseData.toString(), new Object[0]);
      getDataForComponent();
      return;
    }
    notifyFailed(getFullResponse().isIsLoadedFromCache());
    this.mCurrentState.clearState();
  }

  public void stop()
  {
    if (this.mAdaptorListener != null)
      this.mAdaptorListener.forceStop();
    this.mAdaptor.stop();
  }

  public String toString()
  {
    ResponseBean.ResponseData localResponseData = getCurrentAdData();
    StringBuilder localStringBuilder = new StringBuilder().append("\n").append(this.mTag).append(" crid is ");
    if (localResponseData != null);
    for (Object localObject = localResponseData.getCrid(); ; localObject = "undefined yet")
      return localObject + "[mAdaptor=" + this.mAdaptor + ", mBurstlyListener=" + this.mBurstlyListener + ", mBurstlyViewId=" + this.mBurstlyViewId + ", mContext=" + this.mContext + " mDestroyed=" + this.mDestroyed + ", mFailedToShow=" + this.mFailedToShow + ", mIsInterstitial=" + this.mIsInterstitial + ", mIsPrefetchRequest=" + this.mIsPrefetchRequest + ", mLifeCycleListener=" + this.mLifeCycleListener + ", mParent=" + this.mParent + ", mTrackClickRequest=" + this.mTrackClickRequest + ", mTrackShowRequest=" + this.mTrackShowRequest + ", mViewHolder=" + this.mViewHolder + "]";
  }

  static class ParseParamsAsyncTask extends SafeAsyncTask<ResponseObject>
  {
    private final Reference<AdaptorController> mController;

    ParseParamsAsyncTask(AdaptorController paramAdaptorController)
    {
      this.mController = new WeakReference(paramAdaptorController);
    }

    protected void onPostExecute(ResponseObject paramResponseObject)
    {
      AdaptorController localAdaptorController = (AdaptorController)this.mController.get();
      if (localAdaptorController == null)
        return;
      if (!localAdaptorController.mDestroyed)
      {
        localAdaptorController.fillUpWithCurrentResponseData(paramResponseObject);
        try
        {
          localAdaptorController.beginTransaction(paramResponseObject);
          localAdaptorController.setAdaptorListener();
          if (localAdaptorController.isContinueProcessing(paramResponseObject))
          {
            localAdaptorController.mDebugger.logAll();
            AdaptorController.handleServerResponse(localAdaptorController);
            return;
          }
        }
        catch (Throwable localThrowable)
        {
          AdaptorController.handleErrorFlow(localAdaptorController, localThrowable);
          return;
        }
        AdaptorController.LOG.logError(localAdaptorController.mTag, "Parsed response is null or parameters for this network are incorrect.", new Object[0]);
        localAdaptorController.mAdaptorListener.failedToLoad(localAdaptorController.mNetworkName, localAdaptorController.mIsInterstitial, "Unsupported operation");
        localAdaptorController.mParent.setLastError(LastBurstlyError.ERROR_PROCESSING_PARAMS);
        return;
      }
      AdaptorController.LOG.logWarning(localAdaptorController.mTag, "Old Burstly View has been destroyed so safely skip rest of lifecycle.", new Object[0]);
    }

    protected ResponseObject performInBackground()
    {
      AdaptorController localAdaptorController = (AdaptorController)this.mController.get();
      if (localAdaptorController == null)
        return null;
      super.performInBackground();
      return Utils.fromJson(Utils.get3rdPartySdkParams(localAdaptorController.getCurrentAdData().getParms()));
    }
  }

  private static class ViewSwitcher
    implements Runnable
  {
    private final Reference<AdaptorController> mController;

    ViewSwitcher(AdaptorController paramAdaptorController)
    {
      this.mController = new WeakReference(paramAdaptorController);
    }

    public void run()
    {
      AdaptorController localAdaptorController = (AdaptorController)this.mController.get();
      if ((localAdaptorController == null) || (localAdaptorController.mDestroyed))
        return;
      ViewHolder localViewHolder = localAdaptorController.mViewHolder;
      View localView1 = localViewHolder.getPrecachedAdView();
      View localView2 = localViewHolder.getAdView();
      if (localView1 != null);
      for (View localView3 = localView1; ; localView3 = localView2)
      {
        if (localView3 != null)
        {
          localAdaptorController.hideComponent();
          HierarchyAwareLayout localHierarchyAwareLayout = (HierarchyAwareLayout)localView3;
          if (localAdaptorController.isDebugGestureOn())
          {
            localHierarchyAwareLayout.setIsDebugGestureOn(true);
            DebugView localDebugView = new DebugView(localHierarchyAwareLayout.getContext(), localAdaptorController);
            localDebugView.setVisibility(8);
            localDebugView.setLayoutParams(new FrameLayout.LayoutParams(-2, -2));
            localHierarchyAwareLayout.addDebugView(localDebugView);
          }
          localAdaptorController.addComponentToParent(localHierarchyAwareLayout);
          localViewHolder.setAdView(localView3);
        }
        localViewHolder.setPrecachedAdView(null);
        return;
      }
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.AdaptorController
 * JD-Core Version:    0.6.2
 */